﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

[RequireComponent(typeof(Text))]
public class ProjectionCreator : MonoBehaviour
{
    public float projectionDistance = 1f;
    public Color projectionColor = new Color(0, 0, 0, 1);
    private bool waitForActivate = true;
    private GameObject newText;
    // Start is called before the first frame update
    void Start()
    {
        if(waitForActivate)
        {
            waitForActivate = false;
            newText = Instantiate(gameObject, gameObject.transform.parent);
            Destroy(newText.GetComponent<ProjectionCreator>());
            int childCount = newText.transform.childCount;
            for(int i = 0; i < childCount; ++i)
            {
                Destroy(newText.transform.GetChild(0).gameObject);
            }
            newText.name = gameObject.name + "_Salty";
            GetComponent<Text>().color = projectionColor;
            gameObject.GetComponent<RectTransform>().localPosition += new Vector3(projectionDistance, -projectionDistance, 0);
        }
    }

    // Update is called once per frame
    void Update()
    {
        if(newText != null)
        {
            newText.GetComponent<Text>().text = GetComponent<Text>().text;
        }
    }
}
